package leetcode.merge_intervals;

import java.util.Arrays;
import java.util.Comparator;

public class Lc452 {

    public int findMinArrowShots(int[][] points) {
        Arrays.sort(points, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if (o1[0] == o2[0]) {
                    return o1[1] > o2[1] ? 1 : -1;
                }
                return o1[0] > o2[0] ? 1 : -1;
            }
        });

        int ans = points.length;
        int l = points[0][0], r = points[0][1];
        for (int i = 1; i < points.length; i++) {
            if (points[i][0] <= r) {
                ans--;
                l = points[i][0];
                r = Math.min(r, points[i][1]);
            } else {
                l = points[i][0];
                r = points[i][1];
            }
        }
        return ans;
    }

    public static void main(String[] args) {

        Lc452 lc452 = new Lc452();
        int[][] arr = {{-2147483646,-2147483645},{2147483646,2147483647}};
        System.out.println(lc452.findMinArrowShots(arr));

        //-2147483648
        //-2147483645
        //-2147483646
        System.out.println(Integer.MIN_VALUE);
    }
}
